<%-- 
    Document   : createPost
    Created on : Dec 8, 2011, 7:56:24 PM
    Author     : Owner
--%>

<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<%
    String circleID = request.getParameter("CIRC");
    int usrID = Integer.parseInt(session.getAttribute("UserID").toString());
    String post = request.getParameter("postText");
    session.setAttribute("CIRC",circleID);
    Connection conn = null;
    try
    {
        conn = new DBClasses.GetConnection().getConnection();
        //get pageID
        String sql ="SELECT PageID FROM Pages WHERE AssociatedCircleID = "+circleID;
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        rs.next();
        int pageID = rs.getInt("PageID");
        

        sql= "INSERT INTO Posts (Content, Author, PageID)"
            +"VALUES('"+post+"', "+usrID+", "+pageID+")";

        conn.createStatement().execute(sql);
       
    }
    catch(Exception e)
    {
         
        e.printStackTrace();
        response.sendRedirect("CirclePage.jsp");
    }
    
    finally
    {
        try 
        { 
            conn.commit();
            conn.close();
            
            response.sendRedirect("CirclePage.jsp"); 
        }
        catch(Exception e) 
        {  
            e.printStackTrace();
            response.sendRedirect("CirclePage.jsp"); 

        }
    }
%>